<?php

/**
 * 安全设置模型
 * @author yanghj 2014.5.12
 */
class UsersafetyModel extends BaseModel
{
    var $table = 'user_safety';
    var $prikey = 'safety_id';
    var $_name = 'usersafety';
    var $_relation = array('has_member' => array(
            'model' => 'member',
            'type' => HAS_ONE,
            'foreign_key' => 'user_id',
            'refer_key' => 'user_id',
            'dependent' => true), );
    function add_edit($data, $user_id)
    {
        $safety_id = $this->getOne("SELECT safety_id FROM {$this->table} WHERE user_id = {$user_id}");
        if (empty($safety_id)) {
            return $this->add($data);
        } else {
            $this->edit($safety_id, $data);
        }

    }

}

?>